package lexicalUnit;

import chalmersbot.Absyn.SubjectAdjective;
import chalmersbot.Absyn.SubjectBasic;
import chalmersbot.Absyn.SubjectDeterminant;
import chalmersbot.Absyn.SubjectName;
import chalmersbot.Absyn.SubjectNumber;
import chalmersbot.Absyn.SubjectPeriod;
import chalmersbot.Absyn.SubjectPeriodNr;
import chalmersbot.Absyn.SubjectPreposition;
import chalmersbot.Absyn.SubjectPronoun;
import chalmersbot.Absyn.SubjectSmallWord;
import chalmersbot.Absyn.SubjectSpecialWord;
import chalmersbot.Absyn.SubjectWrd.Visitor;

public class CheckSubjectWrd implements Visitor<String, Environ> {

	@Override
	public String visit(SubjectBasic p, Environ env) {
			if (p.subjecttoken_.compareTo("mandatory")==0)
				env.setTarget(Environ.MANDATORY_COURSE);
			else if (p.subjecttoken_.compareTo("optional")==0)
				env.setTarget(Environ.OPTIONAL_COURSE);
			else if (p.subjecttoken_.compareTo("this")==0)
				env.setKeyword(Environ.getLastKeyWord());
		return p.subjecttoken_;
	}

	@Override
	public String visit(SubjectSpecialWord p, Environ env) {
		return p.specialwordtoken_.accept(new CheckSpecialWordToken(), env);
	}

	@Override
	public String visit(SubjectDeterminant p, Environ env) {
		return p.determinanttoken_;
	}

	@Override
	public String visit(SubjectSmallWord p, Environ env) {
		return p.smallwordtoken_;
	}

	@Override
	public String visit(SubjectPronoun p, Environ env) {
		env.setKeyword(Environ.getLastKeyWord());
		return p.pronountoken_;
	}

	@Override
	public String visit(SubjectPeriod p, Environ env) {
		env.setKeywordClass(Environ.PERIOD);
		return p.periodtoken_;
	}

	@Override
	public String visit(SubjectPeriodNr p, Environ env) {
		String period = p.numberrule_.accept(new CheckNumberRule(), env);
		if (period.compareTo("one")==0)
			env.setPeriod(Integer.toString(1));
		else if (period.compareTo("two")==0)
			env.setPeriod(Integer.toString(2));
		else if (period.compareTo("three")==0)
			env.setPeriod(Integer.toString(3));
		else if (period.compareTo("four")==0)
			env.setPeriod(Integer.toString(4));
		else
			env.setPeriod(period);
		return p.periodtoken_ + " " + period;
	}

	@Override
	public String visit(SubjectName p, Environ env) {
		return p.namerule_.accept(new CheckNameRule(), env);
	}

	@Override
	public String visit(SubjectPreposition p, Environ env) {
		return p.preposition_.accept(new CheckPreposition(), env);
	}

	@Override
	public String visit(SubjectAdjective p, Environ env) {
		return p.adjective_.accept(new CheckAdjective(), env);
	}

	@Override
	public String visit(SubjectNumber p, Environ arg) {
		if (arg.getFlag()==Environ.SUBJECT)
			arg.setTarget(Environ.CREDIT);
		return p.credit_.accept(new CheckCredit(), arg);
	}

}
